module.exports = (app) => {
  const { STRING, INTEGER, DATE, BOOLEAN } = app.Sequelize;

  const Slize = app.model.define('slize', {
    slize_name: {
      type: STRING,
      allowNull: false,
      unique: true,
      comment: '用户名，唯一',
    },
    password: {
      type: STRING(64),
      allowNull: false,
      comment: '密码',
    },
    is_admin: {
      type: BOOLEAN,
      allowNull: false,
      defaultValue: 0,
      comment: '是否管理员',
    },
  });

  Slize.findByLogin = async function (login) {
    return await this.findOne({
      where: {
        login,
      },
    });
  };

  // don't use arraw function
  Slize.prototype.logSignin = async function () {
    return await this.update({ last_sign_in_at: new Date() });
  };

  return Slize;
};
